package com.mdtx.database.db;

import com.mdtx.database.AbstractDatabaseOperation;
import com.mdtx.database.type.DbDriverType;
import com.mdtx.database.type.DbType;
import com.mdtx.utils.StringUtil;
import org.springframework.stereotype.Repository;

/**
 * mysql数据库查询实现
 *
 * @author 猫啊
 * @create 2018-06-13 11:09
 **/
@Repository
public class MysqlDataBaseOperation extends AbstractDatabaseOperation {


    private static final String mysqldb = "test";


    @Override
    public String configJdbcUrl() {

        StringBuffer url = new StringBuffer();

        url.append("jdbc:mysql://").append(dbConfig.getIp()).append(":").append(dbConfig.getPort())
                .append("/").append(StringUtil.isEmpty(dbConfig.getDb())?mysqldb:dbConfig.getDb())
                .append("?useUnicode=true&characterEncoding=UTF-8&createDatabaseIfNotExist=true");

        return url.toString();
    }

    @Override
    protected String getDbType() {
        return DbType.MYSQL;
    }

    @Override
    protected String getDbDriverType() {
        return DbDriverType.MYSQL_DRIVER;
    }
}
